function main(defaultParams) {
    debugger;
    const self = this;
    const formPartEle = self.$$element("form_part_80r0ke");
    const formEle = formPartEle.$$getRenderElement();
    const pageRenderElement = this.$$root().$parent.$parent.$parent;

    let extraParams = self.state.extraParams;

    if (formPartEle) {
        formEle.$$validateData().then((res) => {
            if (!res.success) {
                var target = formEle.state.validate.target;
                return;
            } else {
                const formValue = formEle.$$getFormValue()['ds_tbl:t_355f38575f894287a8e40d8af41ae10c'];
                const unitTypeCode = formValue.checkbox_davb9x || []; // 多选机构类型

                const dataForSave = buildUnitInfo(formEle, formValue, unitTypeCode, extraParams);
                console.log("构建后的数据：", dataForSave);

                saveForm(dataForSave).then(res => {
                    console.log(res);
                    let hasError = JSON.parse(res.result).hasError
                    if (hasError) {
                        return;
                    }
                    pageRenderElement.goHistory(-1); // 保存成功后返回
                });
            }
        });
    }


}

function saveForm(data) {
    return api.DATA_SOURCE_EXECUTE(
        "ds_api:8222f7d2-792a-408d-9b80-2e6ed3160030",
        "api",
        [],
        [],
        JSON.stringify(data)
    );
}

function buildUnitInfo(formEle, formValue, unitTypeCode, extraParams) {
    const id = formValue && formValue.id;

    const unitBaseInfo = {
        id,
        unitName: formValue.text_input_5dms7g,
        unitNameAbbr: formValue.text_input_67iog4,
        seniorId: formValue.tree_single_select_4rwjmn,
        regionId: formValue.tree_single_select_5pracq,
        regionName: formValue.tree_single_select_5pracq_hidden_field_4acpcv,
        unitTypeCode: (unitTypeCode || []).join(","),
        socialCreditCode: formValue.text_input_9ahk2x,
        unitLayerLevelCode: formValue.single_select_easbph,
        legalDelegateMan: formValue.text_input_13csj5,
        foundDate: formValue.date_picker_9g98wq,
        postalCode: formValue.text_input_5qekvi,
        email: formValue.text_input_37xmcy,
        fax: formValue.text_input_aoi7tm,
        phone: formValue.text_input_77xzz5,
        address: formValue.textarea_4faevr,
        unitIndustryTypeCode: formValue.single_select_22sj0w,
        verticalManageStateCode: formValue.single_select_ccmbqr,
        verticalManageLevelCode: formValue.single_select_egaqac,
        verticalManageUnit: formValue.tree_single_select_4x8p7i,
        unitStaffSize: formValue.number_input_f49pj6,
        settingBasis: formValue.textarea_bsjpi8,
        publicFlag: formValue.radio_7psxhn
    };

    // 各种类型信息结构体
    const typeHandlers = {
        "5": {
            target: "subjectUnitInfoList", getData: () => ({
                id: extraParams.bmxz_id,
                unitPropertyCode: formValue.single_select_hhkn4k
            })
        },
        "6": {
            target: "subjectUnitInfoList", getData: () => ({
                id: extraParams.ztlb_id,
                subjectCategoryCode: formValue.single_select_4fdqqa,
                lawSubjectId: formValue.tree_single_select_1feg0s
            })
        },
        "7": {
            target: "subjectUnitInfoList", getData: () => ({
                id: extraParams.zfzt2_id,
                lawSubjectId: formValue.tree_single_select_5w24ul
            })
        }
    };

    // 最终构建数据对象
    const result = {
        unitBaseInfo,
        superviseUnitInfoList: [],
        subjectUnitInfoList: [],
        delegationUnitInfoList: [],
        unitRelBizUnitInfoList: []
    };

    // 根据勾选的机构类型收集信息
    [...new Set(unitTypeCode)].forEach(code => {
        const handler = typeHandlers[code];
        if (handler) {
            const data = handler.getData();
            if (Array.isArray(data)) {
                result[handler.target].push(...data);
            } else if (data) {
                result[handler.target].push(data);
            }
        }
    });

    const has5 = unitTypeCode.includes("5");
    const has6 = unitTypeCode.includes("6");
    const has7 = unitTypeCode.includes("7");

    if (has5 || has6 || has7) {
        // 构造 unitRelBizUnitInfoList 数据（以当前表单已有字段来构建）
        result.unitRelBizUnitInfoList.push({
            id: extraParams.jdbm_id,
            relateTypeCode: "1",
            relateUnitId: formValue.tree_single_select_64bsmj,
            relateUnitName: ""
        });
        const relateUnitId = formValue.tree_single_select_6phfuk;

        if (relateUnitId) {
            result.unitRelBizUnitInfoList.push({
                id: extraParams.sjywbm_id,
                relateTypeCode: "2",
                relateUnitId,
                relateUnitName: ""
            });
        }
    }

    return result;
}
